# This file is a part of the open-eBackup project.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
# Copyright (c) [2024] Huawei Technologies Co.,Ltd.
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#!/usr/bin/env python
# _*_ coding:utf-8 _*_

from enum import Enum


class StorageProtocol(int, Enum):
    SAN = 0
    NAS = 1


class StorageType(int, Enum):
    LOCAL = 0  # DORADO
    S3 = 1
    TAPE = 2


class StorageVersion(int, Enum):
    STORAGE_V6 = 0  # DORADO-v6
    OCEANSTOR_V5 = 1


class NasShareType(int, Enum):
    NFS = 0
    CIFS = 1
    FUSE = 2


class DirectoryDistributionModeEnum(int, Enum):
    PERFORMANCE_MODE = 0
    CAPACITY_BALANCE_MODE = 1
    DIRECTORY_BALANCE_MODE = 2
    DIRECTORY_SHUFFLE_MODE = 3
    CONTROLLER_AFFINITY_MODE = 4


class CompressAlgorithmEnum(int, Enum):
    RAPID_COMPRESSION = 0
    DEEP_COMPRESSION = 1


class CifsDomainTypeEnum(int, Enum):
    AD_DOMAIN_USER = 0
    LOCAL_USER = 2


class CifsPermissionEnum(int, Enum):
    READ = 0
    FULL_CONTROL = 1
    FORBIDDEN = 2
    READ_WRITE = 5


class NfsPermissionEnum(int, Enum):
    READ = 0
    READ_WRITE = 1
    FORBIDDEN = 5


class NfsWriteModeEnum(int, Enum):
    SYNC = 0
    ASYNC = 1


class NfsRootPermissionConstraintEnum(str, Enum):
    ROOT_SQUASH = 0
    NO_ROOT_SQUASH = 1


class NfsPermissionConstraintEnum(int, Enum):
    ALL_SQUASH = 0
    NO_ALL_SQUASH = 1


class IpTypeEnum(int, Enum):
    IP_V4 = 0
    IP_V6 = 1


class PortVerification(int, Enum):
    SECURE = 0
    INSECURE = 1


class NetPlaneTypeEnum(str, Enum):
    NAS_STORAGE_KUBERNETES = 'nas.storage.kubernetes.io/ip_address'
    NAS_CONTAINER_KUBERNETES = 'nas.container.kubernetes.io/ip_address'


class LogicPortRunningStatusEnum(int, Enum):
    UNKNOWN = 0
    NORMAL = 1
    RUNNING = 2
    LINK_UP = 10
    LINK_DOWN = 11
    INITIALIZING = 53
    STANDBY = 110


class LogicPortRoleEnum(int, Enum):
    PORT_ROLE_MANAGE = 1
    PORT_ROLE_SERVICE = 2
    PORT_ROLE_MANAGE_SERVICE = 3


class ReturnCode(int):
    SUCCESS = 0
    FAILED = -1
    NOT_EXIST = -2


class HostType(int, Enum):
    SUPPORT_PROTOCOL_NFS = 1
    SUPPORT_PROTOCOL_CIFS = 2
    SUPPORT_PROTOCOL_NFS_CIFS = 3
    SUPPORT_PROTOCOL_ISCSI = 4
    DATA_TURBO_PROTOCOL = 1024
    ALL = 999


# storage's error code
class StorageErrorCode(int):
    FILE_SYSTEM_ALREADY_EXIST = 1077948993
    NFS_SHARE_ALREADY_EXIST = 1077939724
    NFS_ALIAS_EXIST = 1077940485
    CIFS_SHARE_ALREADY_EXIST = 1077939715
    ALREADY_IN_WHITE = 1077939727
    SHARE_CLIENT_NOT_EXIST = 1077939728
    FILE_SYSTEM_NOT_EXIST = 1077939726
    FILE_SYSTEM_ID_NOT_EXIST = 1073752065
    FILE_SYSTEM_SNAPSHOT_EXIST = 1073754142
    HOST_LUN_MAPPING_EXIST = 1073804588
    HOST_EXIST = 1077948993
    NOT_NEED_ADD_NUMBER = 1073947144
    SNAPSHOT_NOT_EXIST = 1077937872
    FS_SNAPSHOT_NOT_EXIST = 1073754118
    WINDOWS_USER_NOT_EXIST = 37749698
    WINDOWS_USER_PASSWORD_SAME = 37749700
    NO_USER_PERMISSION = 1077949058
    AUTH_IP_INCONSISTENCY = 1073793620
    SESSION_INVALIDATED = 1073793621
    LUN_GROUP_HOST_MAPPING_NOT_EXIST = 1073804589
    LUN_HOST_MAPPING_NOT_EXIST = 1073804587
    LUN_HOST_MAPPING_EXIST = 1073804588
    LUN_GROUP_HOST_MAPPING_EXIST = 1073804590
    FC_AND_ISCSI_NOT_EXIST = 1077948996
    REMOTE_DEVICE_NOT_EXIST = 37100137
    REMOTE_USER_NOT_EXIST = 1077949057
    RETURN_SNAP_REACH_FILE_SYSTEM_MAX_NUM = 1073754137
    RETURN_SNAP_REACH_ENTIRE_SYSTEM_MAX_NUM = 1073754138
    RETRUN_SNAP_REACH_PARENT_FS_MAX_NUM = 1073844275
    DTREE_NAME_IS_EXIST = 1077955353
    DTREE_NOT_EXIST = 1077955336
    DTREE_REACH_MAX = 1077955339
    QTREE_REACH_MAX = 1077955083
    DTREE_DIR_EXIST = 1077955354
    FS_ALREADY_EXIST_QOS = 1073810732
    STORAGE_POOL_NOT_EXIST = 1077949965
    RETURN_DTREE_FS_NOT_EXIST = 1077955329
    PARAMETER_ERROR = 50331651
    UNAUTH = -401
    DATA_TURBO_USER_NOT_EXIST = 1077949057
    DATA_TURBO_USER_ALREADY_EXIST = 1077949059
    DATA_TURBO_SHARE_ALREADY_EXIST = 1077941008
    DATA_TURBO_SHARE_NOT_EXIST = 1077941015
    DATA_TURBO_SHARE_DELETE_NOT_EXIST = 1077941000
    DATA_TURBO_USER_OFFLINE = 1077949069
    DATA_TURBO_SHARE_PERMISSION_ALREADY_EXIST = 1077939718
    GLOBAL_SECURE_COMPLIANCE_CLOCK_NOT_EXIST = 1073752089
    GLOBAL_SECURE_COMPLIANCE_CLOCK_ALREADY_EXIST = 1073752094
    NFS_SHARE_CLIENT_NOT_EXIST = 1077939726
    CIFS_SHARE_CLIENT_NOT_EXIST = 1077939717
    CONVERGED_QOS_NOT_EXIST = 33623307
    PACIFIC_OBJECT_NAME_NOT_EXIST = 33623351
    PACIFIC_OBJECT_ALREADY_HAS_QOS = 33623352
    PERFORMANCE_STORAGE_SPACE_NOT_CREATED = 1073952264


StorageNoNeedRetryErrorCode = (
    StorageErrorCode.FILE_SYSTEM_ALREADY_EXIST, StorageErrorCode.NFS_SHARE_ALREADY_EXIST,
    StorageErrorCode.CIFS_SHARE_ALREADY_EXIST, StorageErrorCode.ALREADY_IN_WHITE,
    StorageErrorCode.FILE_SYSTEM_NOT_EXIST, StorageErrorCode.FILE_SYSTEM_SNAPSHOT_EXIST,
    StorageErrorCode.FS_SNAPSHOT_NOT_EXIST, StorageErrorCode.HOST_LUN_MAPPING_EXIST,
    StorageErrorCode.FILE_SYSTEM_ID_NOT_EXIST, StorageErrorCode.WINDOWS_USER_NOT_EXIST,
    StorageErrorCode.HOST_EXIST, StorageErrorCode.SNAPSHOT_NOT_EXIST, StorageErrorCode.NOT_NEED_ADD_NUMBER,
    StorageErrorCode.LUN_HOST_MAPPING_EXIST, StorageErrorCode.LUN_GROUP_HOST_MAPPING_NOT_EXIST,
    StorageErrorCode.FC_AND_ISCSI_NOT_EXIST, StorageErrorCode.LUN_GROUP_HOST_MAPPING_EXIST,
    StorageErrorCode.LUN_HOST_MAPPING_NOT_EXIST, StorageErrorCode.RETURN_SNAP_REACH_FILE_SYSTEM_MAX_NUM,
    StorageErrorCode.RETURN_SNAP_REACH_ENTIRE_SYSTEM_MAX_NUM, StorageErrorCode.RETRUN_SNAP_REACH_PARENT_FS_MAX_NUM,
    StorageErrorCode.DTREE_NOT_EXIST, StorageErrorCode.DTREE_NAME_IS_EXIST, StorageErrorCode.FS_ALREADY_EXIST_QOS,
    StorageErrorCode.SHARE_CLIENT_NOT_EXIST, StorageErrorCode.RETURN_DTREE_FS_NOT_EXIST,
    StorageErrorCode.PARAMETER_ERROR, StorageErrorCode.DATA_TURBO_USER_NOT_EXIST,
    StorageErrorCode.DATA_TURBO_USER_ALREADY_EXIST, StorageErrorCode.DATA_TURBO_SHARE_ALREADY_EXIST,
    StorageErrorCode.DATA_TURBO_SHARE_NOT_EXIST, StorageErrorCode.DATA_TURBO_SHARE_DELETE_NOT_EXIST,
    StorageErrorCode.DATA_TURBO_USER_OFFLINE, StorageErrorCode.DATA_TURBO_SHARE_PERMISSION_ALREADY_EXIST,
    StorageErrorCode.GLOBAL_SECURE_COMPLIANCE_CLOCK_NOT_EXIST, StorageErrorCode.NFS_SHARE_CLIENT_NOT_EXIST,
    StorageErrorCode.CIFS_SHARE_CLIENT_NOT_EXIST, StorageErrorCode.NFS_ALIAS_EXIST,
    StorageErrorCode.DTREE_DIR_EXIST, StorageErrorCode.CONVERGED_QOS_NOT_EXIST,
    StorageErrorCode.PACIFIC_OBJECT_NAME_NOT_EXIST, StorageErrorCode.PACIFIC_OBJECT_ALREADY_HAS_QOS,
    StorageErrorCode.PERFORMANCE_STORAGE_SPACE_NOT_CREATED,
    StorageErrorCode.DTREE_REACH_MAX,
    StorageErrorCode.QTREE_REACH_MAX
)


class RunningStatusEnum(int, Enum):
    NORMAL = 1
    RUNNING = 2
    PRE_COPY = 14
    REBUILT = 16
    SYNCHRONIZING = 23
    SPLIT = 26
    ONLINE = 27
    OFFLINE = 28
    BALANCING = 32
    TO_BE_RECOVERED = 33
    INTERRUPTED = 34
    INVALID = 35
    INACTIVE = 45
    IDLE = 46
    INITIALIZING = 53
    PARTITION_MIGRATING = 96
    DELETING = 106
    STANDBY = 110


class ReadWriteStatusEnum(int, Enum):
    NO_ACCESS = 0
    READ_ONLY = 1
    READ_WRITE = 3


class DtreeParentTypeEnum(int, Enum):
    FILESYSTEM = 40


class DtreeSecurityStyleEnum(int, Enum):
    MIXED = 0
    NATIVE = 1
    NTFS = 2
    UNIX = 3


class SnapshotStatusEnum(int, Enum):
    UNKNOWN = 0
    ACTIVATED = 43
    ROLLINGBACK = 44
    UNACTIVATED = 45
    INITIALIZING = 53
    DELETING = 106


class AssociateObjTypeEnum(int, Enum):
    LUN = 11
    HOSTGROUP = 14
    HOST = 21
    LUNGROUP = 256


class RollbackStatusEnum(int, Enum):
    ROLLBACK_STATUS_IDLE = 0
    ROLLBACK_STATUS_RUNNING = 1
    ROLLBACK_STATUS_PAUSED = 2
    ROLLBACK_STATUS_COMPLETE = 3


class SpaceAllocationType(int, Enum):
    THIN_FILE_SYSTEM = 1


class QosSchedulingPolicy(int, Enum):
    ONCE = 0
    DAILY = 1
    WEEKLY = 2


class QosPolicyType(int, Enum):
    NORMAL = 0
    HIERARCHICAL = 1


class SecresAccessEnum(int, Enum):
    ACCESS_DENIED = 1
    READ_ONLY = 2
    READ_WRITE = 3


class SpaceSelfAdjustingMode(int, Enum):
    CLOSED = 0
    AUTOMATIC_CAPACITY_EXPANSION = 1
    AUTOMATIC_CAPACITY_EXPANSION_AND_REDUCTION = 2


MAX_NAME_LENGTH = 31
LINUX_TYPE = 0
HOST_TYPE = 21
FILE_SYSTEM_SECTOR_IN_BYTES = 512
NUM_50 = 50
NUM_99 = 99
NUM_1024 = 1024
FILE_SYSTEM_TYPE = 40
SMART_QOS_TYPE = 230
FILE_SYSTEM_BANDWIDTH = 511
ROLL_BACK_SPEED = 3
MAX_ROLLBACK_RATE = 100
STATUS_QUERY_TIMEOUT_SEC = 100
STATUS_QUERY_INTERVAL_SEC = 3
MAX_STORAGE_RETRIES = 3
STORAGE_RETRY_INTERVAL_TIME_SEC = 30
QOS_NAME_MAX_LENGTH = 31
QOS_EVERTY_DAY = 1
QOS_ZERO_CLOCK = "00:00"
QOS_TWNETY_FOUR_HOUR = 86400
QOS_MAX_IO_PS_BAND_WITH_VALUE = 999999999
QOS_MIN_IO_PS_VALUE = 100
QOS_MIN_BAND_WITH_VALUE = 1
QOS_MIN_BURST_TIME = 1
QOS_MAX_BURST_TIME = 999999999
QOS_LATENCY_500US = 500
QOS_LATENCY_1500US = 1500
PROTECT_ENGINE_E_DMA_DOMAIN = 'protectengine-e-dma'
PROTECT_ENGINE_E_DMA_PORT = '30070'
DATA_TURBO_ROLE_ID = 1029
DATA_TURBO_SCOPE = 0
DATA_TURBO_VSTOREID = 0
DEFAULT_VSTOREID = 0
DATA_TURBO_PROTOCOL = '1024'
WORM_TYPE = 1
WORM_UNIT = 48
MIN_PROTECT_TIME_UNIT = 46
WORM_PERIOD = 70
WORM_MIN_PROTECT_PERIOD = 0
KERBEROS_5P_OPEN = 1
CRL_CONTENT_INDEX = 1
AUTO_GROW_THRESHOLD_PERCENT = 85
MAX_LOGIC_CAPACITY_FOR_FILESYSTEM = 70368744177664
DEFAULT_ALARM_CAPACITY_THRESHOLD = 90
CONVERGED_QOS_NAME_MAX_LENGTH = 63
E6000_DEPLOY_TYPE = 'd7'
E1000_DEPLOY_TYPE = 'd8'

# e6000场景不支持复制
DEPLOY_TYPE_GROUP_NO_REPLICATION = {'d7'}

# e6000场景没有数据迁移
DEPLOY_TYPE_GROUP_NO_MIGRATING = {'d7'}


class QosScale(int, Enum):
    # pacific qos控制维度
    NAMESPACE = 0
    CLIENT = 1
    ACCOUNT = 2
    USER = 4
    HIDDEN_FS = 5
    DIRECTORY = 6
    USER_GROUP = 7


class QosMode(int, Enum):
    BY_USAGE = 1
    BY_PACKAGE = 2
    MANUAL = 3


class QosReturnCode(int, Enum):
    QosNotExist = 33623307
    ObjectNameNotExist = 33623351
